/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package net.tygzs.minerpg.CommandExecutor.MineItem;

import net.tygzs.minerpg.Configuration.Item.RPGItem;
import net.tygzs.minerpg.Main;
import org.bukkit.Bukkit;
import static org.bukkit.Bukkit.getServer;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

/**
 *
 * @author Administrator
 */
public class Command_Give
{

    public static void GiveItem(CommandSender sender, String ItemName, String PlayerName)
    {
        Player player = getServer().getPlayer(PlayerName);
        if (player == null)
        {
            sender.sendMessage(ChatColor.RED + "玩家不在线");
            return;
        }
        if (Main.getPluginConfig().getItem(ItemName) == null)
        {
            sender.sendMessage(ChatColor.RED + "物品不存在");
            return;
        }
        ItemStack is = RPGItem.BuildItem(Main.getPluginConfig().getItem(ItemName));
        player.getInventory().addItem(is);
        if (!sender.getName().equals(Bukkit.getConsoleSender().getName()))
        {
            sender.sendMessage(ChatColor.GREEN + "成功给予玩家" + PlayerName + "一个" + ItemName);
        }
    }
}
